package com.acxy.weixin.service;

import com.acxy.ants.common.kit.HttpKit;
import com.acxy.ants.core.annotation.Service;
import com.acxy.ants.core.annotation.Value;
import com.acxy.weixin.kit.AccessToken;
import com.acxy.weixin.kit.ApiResult;

/**
 * @author MrShun
 * @version 1.0
 * @Date 2017-11-04
 */
@Service
public class WxTplMsgService {

    @Value("wx.appId")
    private String appId;

    @Value("wx.appSecret")
    private String appSecret;

    //获取模板消息列表
    private final static String template_list_api = "https://api.weixin.qq.com/cgi-bin/template/get_all_private_template?access_token=ACCESS_TOKEN";

    //发送模板消息 POST
    private final static String send_template_api = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=ACCESS_TOKEN";

    /**
     * 获取模板消息列表
     * @return
     */
    public ApiResult getTplMsgList(){
        String accessToken = AccessToken.getAccessTokenStr(appId, appSecret);
        String result = HttpKit.sendGET(template_list_api.replace("ACCESS_TOKEN", accessToken));
        return new ApiResult(result);
    }

    /**
     * 发送模板消息
     * @return
     */
    public ApiResult sendTplMsg(String jsonStr){
        String accessToken = AccessToken.getAccessTokenStr(appId, appSecret);
        String result = HttpKit.sendPost(send_template_api.replace("ACCESS_TOKEN", accessToken), jsonStr);
        return new ApiResult(result);
    }
}
